var RE_NAME = /^[A-Za-z ]{5,}$/;
var RE_USERNAME= /^[A-Za-z0-9._]{5,}$/;
var RE_EMAIL = /^(\w+[\-\.])*\w+@(\w+\.)+[A-Za-z]+$/;
var RE_PASSWORD = /.{6,}$/;
var RE_PROFIL = /^.+\.((jpg)|(JPG)|(png)|(PNG)|(bmp)|(BMP)|(JPEG)|(JPEG))$/;
var RE_TANGGAL = /^((((19|20)(([02468][048])|([13579][26]))-02-29))|((20[0-9][0-9])|(19[0-9][0-9]))-((((0[1-9])|(1[0-2]))-((0[1-9])|(1\d)|(2[0-8])))|((((0[13578])|(1[02]))-31)|(((0[1,3-9])|(1[0-2]))-(29|30)))))$/;
var RE_LOKASI = /.{5,}/;

function check(form) { 
	var name = form.name.value;
	var username = form.username.value;
	var email = form.email.value;
	var password = form.password.value;
	var lokasi = form.location.value;
	var tanggal = form.birth.value;
	var errors = [];
	if (!RE_NAME.test(name)){
		errors[errors.length] = "Nama anda tidak valid.";
		}
	if (!RE_USERNAME.test(username)){
		errors[errors.length] = "Username anda tidak valid.";
		}
	if(!RE_EMAIL.test(email)){
		errors[errors.length] = "Email address anda tidak valid";
		}
	if(!RE_PASSWORD.test(password)){
		errors[errors.length] = "Password anda tidak valid.";
		}
	if(!RE_TANGGAL.test(tanggal)){
		errors[errors.length] = "Tanggal lahir masukan anda tidak valid";
		}
	if(!RE_LOKASI.test(lokasi)){
		errors[errors.length] = "Lokasi anda tidak valid.";
		}	
	if (errors.length > 0) {
  		reportErrors(errors);
  		return false;
		 }
 	 alert("Succeed");
//0-in semuanya
	form.nama.value = "";
	form.username.value = "";
	form.email.value = "";
	form.password.value = "";
	form.FileFotoProfil.value = "";
	form.cpassword.value = "";
	form.lokasi.value = "";
	form.tanggal.value = "";
	 
	 return true;
		
}

function reportErrors(errors){
 var msg = "Ada beberapa kesalahan\n";
 for (var i = 0; i<errors.length; i++) {
  var numError = i + 1;
  msg += "\n" + numError + ". " + errors[i];
 }
 alert(msg);
}
